package com.um.info.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cs.framework.common.util.CommonUtils;
import com.cs.framework.jdbc.common.dao.CommonDao;
import com.um.info.dto.base.UmUserDto;
import com.um.info.service.UmUserService;

/**
 * UM用户
 * 
 * @author hedongzhou
 * 
 */
@Service("umUserService")
public class UmUserServiceImpl implements UmUserService {

	@Resource
	private CommonDao commonDao;

	/**
	 * 获取UM用户
	 * 
	 * @param userId
	 *            用户名
	 * @return
	 */
	public UmUserDto get(String userId) {
		return commonDao.getById(UmUserDto.class, userId);
	}

	/**
	 * 查询UM用户总数
	 * 
	 * @param umUserDto
	 * @return
	 */
	public int count(UmUserDto umUserDto) {
		return commonDao.count("UmUser.query", umUserDto);
	}

	/**
	 * 查询UM用户列表
	 * 
	 * @param umUserDto
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public <T extends UmUserDto> List<T> query(T umUserDto) {
		return (List<T>) commonDao.selectList("UmUser.query", umUserDto, umUserDto, umUserDto.getClass());
	}

	/**
	 * 新增UM用户
	 * 
	 * @param umUserDto
	 * @return
	 */
	public UmUserDto save(UmUserDto umUserDto) {
		UmUserDto entity = get(umUserDto.getUserId());
		if (entity != null) {
			CommonUtils.throwRun("该用户名【" + umUserDto.getUserId() + "】已存在");
		}

		return commonDao.save(umUserDto);
	}

	/**
	 * 更新UM用户
	 * 
	 * @param umUserDto
	 *            用户信息
	 * @return
	 */
	public UmUserDto update(UmUserDto umUserDto) {
		return commonDao.update(umUserDto);
	}

}
